package com.timberwood.controller;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.timberwood.model.dao.CategoryDAO;
import com.timberwood.model.entity.Category;

public class CategoryAction extends ActionSupport{
	private static final long serialVersionUID = -1682533867154609212L;
	
	CategoryDAO categoryDAO;
	public CategoryAction() {
		categoryDAO=new CategoryDAO();
	}
	
	
	public List<Category> listCate;
	
	public List<Category> getListCate() {
		return listCate;
	}
	
	public String cateBusyA(){
		listCate=categoryDAO.sleCategoryBusy();
		return SUCCESS;
	}
	
	public String cateStopSellingA(){
		listCate=categoryDAO.sleCateStopSelling();
		return SUCCESS;
	}
	
	
	private String cateName;
	public void setCateName(String cateName) {
		this.cateName = cateName;
	}

	public String addCate(){
		categoryDAO.insertCategory(new Category(cateName, true));
		return SUCCESS;
	}
	
	public String delCate(){
		String ID=ServletActionContext.getRequest().getParameter("ID");
		categoryDAO.deleteCate(Integer.parseInt(ID));
		return SUCCESS;
	}
	
	public String editCate(){
		String ID=ServletActionContext.getRequest().getParameter("ID");
		categoryDAO.deleteCate(Integer.parseInt(ID));
		return SUCCESS;
	}
	
	
		
	
	
	
}
